#enque_thread_request.py
import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

from xmw.tianya import error_tianya
from xmw.tianya.bot import *
from xmw import counter
import xmw

import os

class MainPage(xmw.RequestHandler):


        
    def get(self):
        e=None
        #if  not (self.request.GET.has_key('thread_id') and self.request.GET.has_key('url')):
        if  not ( self.request.GET.has_key('url')):
            e = error_tianya.ARGUMENT_FAULT("/enque_thread_request?url=XXXX, where now it is %s"%str(self.request))
        else:
            #thread_id   =self.request.GET['thread_id']
            url =   self.request.GET['url']
            seq=    counter.get_and_inc_count()
            #req=ThreadRequest(thread_id=thread_id,url=url,seq=seq)
            req=ThreadRequest(url=url,seq=seq)
            
            req.put()
            e=error_tianya.OK("/enque_thread_request?url=%s"%(url))
        
        self.render_error(e)
        

def main():
  application = webapp.WSGIApplication(
                                       [('/enque_thread_request', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
  